var app = getApp();

Page({
    data: {
        monry: 0,
        idx: 0,
        recharge: [],
        packagedatas: [],
        goods: [],
        dy_mb_recharge: [],
        issend: !1,
        statusval: 0
    },
    choseTxtColor: function(a) {
        var t = a.currentTarget.dataset.idx, e = this.data.recharge[t].packageid, s = [];
        for (var o in this.data.packagedatas) this.data.packagedatas[o].id == e && (s = this.data.packagedatas[o].goods);
        this.setData({
            idx: t,
            goods: s
        });
    },
    sendmoban: function() {
        this.data.statusval < 5 || (5 == this.data.statusval && app.util.request({
            url: "entry/wxapp/my",
            data: {
                op: "rechargedy",
                tid: this.data.tid
            },
            success: function(a) {}
        }), wx.redirectTo({
            url: "../../fastshop/rechargeSuccess/rechargeSuccess"
        }));
    },
    myform: function(a) {
        var o = this, t = this.data.recharge, e = this.data.idx, s = t[e].fee;
        this.data.monry;
        "" != t[e].fee ? "" != a.detail.value.mode ? wx.showModal({
            title: "确认充值",
            content: "确认充值" + s + "元？",
            success: function(a) {
                a.confirm && (app.util.showLoading(), app.util.request({
                    url: "entry/wxapp/my",
                    data: {
                        op: "pay_recharge",
                        idx: e
                    },
                    success: function(a) {
                        console.log(a);
                        var t = a.data, s = t.data.tid;
                        t && t.data && !a.data.errno && wx.requestPayment({
                            timeStamp: a.data.data.timeStamp,
                            nonceStr: a.data.data.nonceStr,
                            package: a.data.data.package,
                            signType: "MD5",
                            paySign: a.data.data.paySign,
                            success: function(a) {
                                o.data.tid = s;
                                var t = function a(t) {
                                    app.util.request({
                                        url: "entry/wxapp/payquery",
                                        showLoading: !1,
                                        data: {
                                            tid: t
                                        },
                                        success: function(a) {
                                            console.log(a.data.data), app.globalData.userInfo = a.data.data, wx.showToast({
                                                title: "充值成功"
                                            }), o.setData({
                                                monry: a.data.data.amount
                                            }), o.data.statusval = 4 | o.data.statusval, o.sendmoban();
                                        },
                                        fail: function() {
                                            setTimeout(function() {
                                                a(t);
                                            }, 1e3);
                                        }
                                    });
                                };
                                t(s);
                                var e = wx.getSystemInfoSync().SDKVersion;
                                0 <= app.util.compareVersion(e, " 2.8.2 ") && o.data.dy_mb_recharge && 0 < o.data.dy_mb_recharge.length && wx.requestSubscribeMessage({
                                    tmplIds: o.data.dy_mb_recharge,
                                    success: function(a) {
                                        "accept" == a[o.data.dy_mb_recharge[0]] ? o.data.statusval = 1 | o.data.statusval : o.data.statusval = 2 | o.data.statusval, 
                                        o.sendmoban();
                                    },
                                    complete: function(a) {
                                        setTimeout(function() {
                                            t(s);
                                        }, 500);
                                    }
                                });
                            },
                            fail: function(a) {}
                        });
                    },
                    fail: function(a) {
                        wx.showModal({
                            title: "系统提示",
                            content: a.data.message ? a.data.message : "错误",
                            showCancel: !1,
                            success: function(a) {
                                a.confirm;
                            }
                        });
                    }
                }));
            }
        }) : wx.showToast({
            title: "请选择支付方式",
            icon: "none"
        }) : wx.showToast({
            title: "请选择充值面额",
            icon: "none"
        });
    },
    click_off: function() {
        this.setData({
            isShow: !this.data.isShow
        });
    },
    onLoad: function(a) {
        var n = this;
        n.setData({
            webset: app.globalData.webset,
            monry: app.globalData.userInfo.amount
        }), app.util.request({
            url: "entry/wxapp/my",
            showLoading: !1,
            data: {
                op: "recharge"
            },
            success: function(a) {
                var t = a.data, e = t.data.recharge.value[0].packageid;
                n.data.dy_mb_recharge = t.data.dy_mb_recharge;
                var s = [];
                for (var o in t.data.packagedatas) t.data.packagedatas[o].id == e && (s = t.data.packagedatas[o].goods);
                n.setData({
                    recharge: t.data.recharge.value,
                    packagedatas: t.data.packagedatas,
                    goods: s
                });
            }
        });
    },
    onReady: function() {
        app.look.navbar(this);
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        var e = this;
        app.util.request({
            url: "entry/wxapp/my",
            showLoading: !1,
            data: {
                op: "recharge"
            },
            success: function(a) {
                wx.stopPullDownRefresh();
                var t = a.data;
                t.data.money && e.setData({
                    monry: t.data.money
                });
            }
        });
    },
    onReachBottom: function() {}
});